package com.lxyk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.lxyk.mapper.WorkerMapper;
import com.lxyk.pojo.Customer;
import com.lxyk.pojo.Worker;
import com.lxyk.service.WorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkerServiceImpl implements WorkerService {
    @Autowired
    private WorkerMapper workerMapper;
    @Override
    public List<Worker> queryWorker() {
        List<Worker> workerList = workerMapper.selectList(null);
        return workerList;
    }//不要了，我们要分页查询

    //分页查询
    @Override
    public PageInfo<Worker> listWorker(Worker worker, Integer pageNum, Integer pageSize) {
        List<Worker> workerList = workerMapper.listWorker(worker);

        return new PageInfo<>(workerList);
    }

    @Override
    public int addSalary(Integer wid, Integer workerSalary) {
         return workerMapper.addSalary(wid,workerSalary);
    }

    @Override
    public int saveWorker(Worker worker) {
        return workerMapper.insert(worker);
    }

    @Override
    public Worker getWorkerById(Integer wid) {
        QueryWrapper<Worker>qw=new QueryWrapper<>();
        qw.eq("wid",wid);
        return workerMapper.selectOne(qw);
    }

    @Override
    public int updateWorker(Worker worker) {
        QueryWrapper<Worker>qw=new QueryWrapper<>();
        QueryWrapper<Worker> wid = qw.eq("wid", worker.getWid());
        return workerMapper.update(worker,qw);
    }




}
